/*
 * esp8266.h
 *
 *  Created on: Aug 2, 2021
 *      Author: 86181
 */
#ifndef INC_ESP8266_H_
#define INC_ESP8266_H_

#define esp8266_huart               &huart2
#define g_atcmd_rxbuf            g_uart2_rxbuf
#define g_atcmd_bytes            g_uart2_bytes

#define clear_uart2_buf()     do { memset(g_atcmd_rxbuf, 0, sizeof(g_atcmd_rxbuf)); \
								 g_atcmd_bytes=0; } while(0)

#define CONFIG_DEBUG_WIFI

#ifdef CONFIG_DEBUG_WIFI
#define esp_printf(format,args...) printf(format, ##args)
#else
#define esp_printf(format,args...) do{} while(0)
#endif

extern int send_atcmd(char *atcmd, unsigned int timeout);

extern int atcmd_send_data(unsigned char *data, int bytes, unsigned int timeout);

extern int esp8266_wifi_init(void);

extern int esp8266wifi_join_network(char *id, char *password);

extern int esp8266wifi_ping(char *id);

extern int esp8266wifi_socket_connect(char *servip, int port);

extern int esp8266_sock_disconnect(void);

extern int esp8266_sock_send(unsigned char *data, int bytes);

extern int esp8266_sock_recv(unsigned char *buf, int size);

#endif

